#ifndef VLMODEL_H
#define VLMODEL_H
#include <cv.h>

#include <QList>
#include <qsettings.h>
#include <qstringlist.h>

#include "mydefination.h"

enum eVideoSourceType{File, URL};
struct VideoSource_t{
    QString sourceName;
    eVideoSourceType sourceType;
    QString source;
    QList<CvPoint> ROI;
    int motionThreshold;
    int timeSwitch;

    char* SourceName(){
        QByteArray ba = sourceName.toLatin1();
        return ba.data();
    }
    char* Source(){
        QByteArray baSource = source.toLatin1();
        return baSource.data();
    }
};
typedef struct VideoSource_t VideoSource;

class VLModel
{
public:
    VLModel();
    ~VLModel();

    bool Verbose() {return verbose; }
    int GMotionThreshold() {return gMotionThreshold; }
    int GTimeSwitch() {return gTimeSwitch; }
    QList<VideoSource> VideoList() {return videoList; }
    VideoSource getVideoSource(int sourceIndex);

private:
    QList<VideoSource> videoList;
    bool verbose;
    int gMotionThreshold;
    int gTimeSwitch;

    int workingSourceIndex;

    int readIniFile();
    bool writeIniFile();
    QString pointList2String(QList<CvPoint> pointList);
    QList<CvPoint> string2PointList(QString strOfPoints);

public:
    inline void switchVerboseMode() {verbose = !verbose; }
    inline void setVerbose(bool _verbose) { verbose = _verbose;}
    inline void setGlobalMotionThreshold(int _gMotionThreshold) { gMotionThreshold = _gMotionThreshold;}
    inline void setGlobalTimeSwitch(int _gTimeSwitch){ gTimeSwitch = _gTimeSwitch;}
    void setGlobalSettings(bool _verbose, int _gMotionThreshold, int _gTimeSwitch);
    void setROI(QList<CvPoint> list);
    void clearROI();

    void addVideoSource(VideoSource _videoSource);
    int removeVideoSource(int _videoSourceIndex);
    void clearVideoSource();

};

#endif // VLMODEL_H
